from matplotlib import pyplot as plt
import matplotlib,csv
reader=csv.reader(open("../Wine Reviews/dataset/winemag-data_first150k.csv","r",encoding="utf-8"))
matplotlib.rcParams['font.sans-serif']=['SimHei']   # 用黑体显示中文
matplotlib.rcParams['axes.unicode_minus']=False     # 正常显示负号
points,prices=[],[]
for row in reader:
    if len(row[4])>0:points.append(row[4]) #索引表示所在列
    if len(row[5])>0:prices.append(row[5])
points=[float(points[i]) for i in range(1,len(points))]
prices=[float(prices[i]) for i in range(1,len(prices))]
def histogram(datas,xlabel,title):
    plt.ticklabel_format(style="plain")
    plt.hist(datas)
    plt.xlabel(xlabel)
    plt.ylabel("频数")
    plt.title(title)
    plt.show()
def box(datas,title):
    plt.ticklabel_format(style="plain")
    plt.title(title)
    plt.boxplot(datas,showmeans=True,showfliers=False)
    plt.show()
histogram(points,"评分","评分points直方图")
histogram(prices,"价格","价格prices直方图")
box(points,"评分points盒图")
box(prices,"价格prices盒图")
